package com.example.demo.Component;

import com.example.demo.UserInfo.UserInfo;
import com.example.demo.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Primary;
import org.springframework.stereotype.Component;

@Component

public class UserComponent {
    /**
     * DI : 依赖注入/对象注入
     */
////    1. 属性注入
//    @Autowired
//    public UserService service;


    //2. Setter 方法注入
//    public UserService service2;
//    @Autowired
//    public void setService2(UserService service2) {
//        this.service2 = service2;
//    }


//    //3. 构造方法注入
//    //有多个构造方法,默认使用无参的构造方法,需使用  @Autowired 指明
//    public UserService service3;

//    public UserComponent() {
//    }
//    @Autowired
//    public UserComponent(UserService service3) {
//        this.service = service3;
//    }

    public void  sayHi(){
        System.out.println("Hi UserComponent...");

    }
//    @Primary
   @Bean( {"u1","u2"})

    public UserInfo userInfo(){
        return  new UserInfo(1,"zhangsan");
    }

   @Bean
    //  @Bean 必须搭配五大注解类使用
    public UserInfo userInfo2(){
        return new UserInfo(2,"lisi");
    }
}
